package cn.wolfcode.web.controller;


import cn.wolfcode.common.web.Result;
import cn.wolfcode.domain.OrderInfo;
import cn.wolfcode.service.IOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.Map;

/**
 * Created by lanxw
 */
@RestController
@RequestMapping("/orderPay")
@RefreshScope
public class OrderPayController {
    @Autowired
    private IOrderInfoService orderInfoService;

    @RequestMapping("/pay")
    public Result<String> pay(String orderNo, Integer type){
        if(OrderInfo.PAYTYPE_ONLINE.equals(type)){
            //在线支付
            return orderInfoService.payOnline(orderNo);
        }else{
            // 积分支付
            return Result.success();

        }
    }

    /**
     * 异步回调
     * @return
     */
    @RequestMapping("/notifyUrl")
    public String notifyUrl(@RequestParam Map<String,String>params){
        // 利用支付宝对SKD验证签名
        Result<Boolean> result = new Result<Boolean>();
        result.setData(true);
        if(result == null || result.hasError()){
            return "fail";
        }
        if(result.getData()){
            //通过验证签名
            // 改一下订单状态，变成已经支付了
        }
        return "success";
    }
}
